'''
网页中嵌套了一个子网页，需要切换到iframe中，才能操作
driver.switch_to.frame(iframe)  切换操作
driver.switch_to.default_content() # 切换到最外层
driver.switch_to.parent_frame() # 切换到上一层
如果iframe只切换了一次，则最外层就是上一层
'''

import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Edge()
driver.get("http://127.0.0.1/ranzhi/www/")
time.sleep(3)

# 用户名密码
driver.find_element("xpath",'//*[@id="account"]').send_keys("admin")
driver.find_element("xpath",'//*[@id="password"]').send_keys("123456")
# 点击登录
driver.find_element("xpath",'//*[@id="submit"]').click()
time.sleep(2)

# 点击后台管理
driver.find_element("xpath",'//*[@id="s-menu-superadmin"]/button/i').click()

# 切换到iframe
# 定位到iframe
iframe = driver.find_element("id","iframe-superadmin")
driver.switch_to.frame(iframe)

# 点击添加成员
driver.find_element("class name","shortcut.user").click()

# 切换到上一层
driver.switch_to.default_content()
time.sleep(10)
# driver.switch_to.parent_frame()

# 点击签退
driver.find_element("class name","sign.signout").click()

time.sleep(20)
